
if(/www\.google\.com\/reader\//.test(location.href))
{
  var loadJqflag = false;
  function documentWait()
  {
	//wait until head element was found
	var head = document.getElementsByTagName('head');
	if(!head || head.length != 1){
		console.log("waiting head..");
		window.setTimeout(documentWait,100);return;
	}
	//wait until google script was loaded
	if(!window.$){
		console.log("waiting Google script ..");
	 	window.setTimeout(documentWait,100);return;
	}

	//append jquery script to head
	if(!loadJqflag){
	    jq = document.createElement('script');
	    jq.id = 'jQueryScript';
	    jq.src = chrome.extension.getURL("jquery-1.7.1.min.js");
    	head[0].appendChild(jq);
			loadJqflag = true;
	}
	//wait util jquery was loaded
	if(!window.jQuery){
		console.log("waiting JQuery..");
		window.setTimeout(documentWait,100);
		return;
	}

	 console.log("initialization finished.");
	 //append customscript

/*	 var script = document.createElement('script');
	 script.id = 'customscript';
	 script.src = chrome.extension.getURL("xg-reader.js");
	 head[0].appendChild(script);
*/
 	//main
	jQuery.noConflict(); 
	jQuery(document.body).hide(); 
	CallCustomFunction();

  }

  function CallCustomFunction(){			
			//wait until body was found
			if(!document.body){
			 console.log("waiting body..");
			 window.setTimeout(CallCustomFunction,100);
			}
			else{
				try{	
						(function runCustomFunction(){
							window.cf = window.CustomFunction;
							if(!window.cf || !(typeof window.cf === 'function')){										
								console.log("waiting customfunction..");
								setTimeout(runCustomFunction, 100);
								return;
							}else{
								window.cf();
							}
						})();
								
				}catch(err){
					console.log("Load failed. ErrMsg:"+err);
				}
			}					
	}


  documentWait();
}


